﻿@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
    //page title
    ViewBag.Title = T("Admin.Configuration.Languages.Localization").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-content.png")" alt="" />
        @T("Admin.Configuration.Languages.Localization")
    </div>
</div>
@if (ViewBag.AllLanguages != null)
{
    <table class="adminContent" style="margin-bottom: 10px;">
        <tr>
            <td class="adminTitle">
                @T("Admin.Configuration.Languages.Select")
            </td>
            <td class="adminData">
                @Html.DropDownList("localeresource-language", (IEnumerable<SelectListItem>)ViewBag.AllLanguages, new { onchange = "onLocaleResourceLanguageSelected(this.value);" })
                <script type="text/javascript">
                    function onLocaleResourceLanguageSelected(languageid) {
                        window.location = '@(Url.Action("Resources") + "?languageId=")' + languageid;
                    }
                </script>
            </td>
        </tr>
    </table>
}
<table class="adminContent">
    <tr>
        <td>
            @T("Admin.Configuration.Languages.Resources.Description")
        </td>
    </tr>
    <tr>
        <td>
            <div id="resources-grid"></div>

            <script>
                $(document).ready(function () {
                    $("#resources-grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@Html.Raw(Url.Action("Resources", "Language", new { languageId = ViewBag.LanguageId }))",
                                    type: "POST",
                                    dataType: "json",
                                    contentType: "application/json"
                                },
                                create: {
                                    url: "@Html.Raw(Url.Action("ResourceAdd", "Language", new { languageId = ViewBag.LanguageId }))",
                                    type: "POST",
                                    dataType: "json"
                                },
                                update: {
                                    url:"@Html.Raw(Url.Action("ResourceUpdate", "Language"))",
                                    type: "POST",
                                    dataType: "json"
                                },
                                destroy: {
                                    url: "@Html.Raw(Url.Action("ResourceDelete", "Language"))",
                                    type: "POST",
                                    dataType: "json"
                                },
                                parameterMap: function(data, operation) {
                                    if (operation != "read") {
                                        return data;
                                    } else {
                                        //for some reasons only such "Filter" data be parsed
                                        return JSON.stringify(data);
                                    }
                                }
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors",
                                model: {
                                    id: "Id",
                                    fields: {
                                        Name: { editable: true, type: "string" },
                                        Value: { editable: true, type: "string" },
                                        Id: { editable: false, type: "number" }
                                    }
                                }
                            },
                            requestEnd: function (e) {
                                if (e.type == "create" || e.type == "update") {
                                    this.read();
                                }
                            },
                            error: function (e) {
                                display_kendoui_grid_error(e);
                                // Cancel the changes
                                this.cancelChanges();
                            },
                            pageSize: @(gridPageSize),
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        pageable: {
                            refresh: true
                        },
                        sortable: true,
                        toolbar: ["create"],
                        editable: {
                            confirmation: false,
                            mode: "inline"
                        },
                        filterable: {
                            extra: false,
                            operators: {
                                string: {
                                    contains: "Contains",
                                    eq: "Is equal to"
                                }
                            }
                        },
                        scrollable: false,
                        columns: [{
                            field: "Name",
                            title: "@T("Admin.Configuration.Languages.Resources.Fields.Name")",
                            width: 300,
                            filterable: true,
                            sortable: true
                        }, {
                            field: "Value",
                            title: "@T("Admin.Configuration.Languages.Resources.Fields.Value")",
                            width: 300,
                            filterable: true,
                            sortable: true

                        }, {
                            command: [{
                                name: "edit",
                                text: "@T("Admin.Common.Edit")"
                            }, {
                                name: "destroy",
                                text: "@T("Admin.Common.Delete")"
                            }],
                            width: 200,
                            filterable: false
                        }]
                    });
                });

            </script>
        </td>
    </tr>
</table>
